#include<iostream>
using namespace std;

class Animal {
  public:
    virtual void speak() = 0;
    virtual ~Animal() {  // 必须是虚析构函数，Cat * cat = new Cat(10); delete cat时才会调用 Cat的析构函数
      cout << "animal析构函数执行" << endl;
    }
};

class Cat : public Animal {
  public:
    Cat(int age) {
      m_age = new int(age);
    }
    void speak(){
      cout << "小猫在说话" << endl;
    };
    int *m_age;
    ~Cat() {
      cout << "cat析构函数执行" << endl;
      if(m_age != NULL) {
        delete m_age;
        m_age = NULL;
      }
    }
};


void test01(Animal *animal) {
  animal->speak();
  delete animal;
};

int main(){
  Cat * cat = new Cat(10);
  test01(cat);
  return 0;
}
